package com.hisense.ovcloud.warehouse;

public class Constants {
    public final static String DKEY_REDIS_PREFIX = "dynkeyt:";
    public final static String DKEY_REDIS_FIELD = "dynkeyt";

    public final static int RESULT_SUCCESS = 0;
    public final static int RESULT_FAILED = 1;

    public final static String AESKEY_PREFIX = "aes_";

    public final static String REST_SCHEMA_HTTP = "http://";

    public static class JulinkWarehouse {
        public final static String SHARDING_TABLES_PREFIX_IN_YAML = "device_warehouse___";
        public final static int ACTIVATED = 2;
        public final static int NOT_ACTIVATED = 1;
        public final static String WIFI_ID_TO_REPLACE = "__WIFI_ID_TO_REPLACE__";
        public final static String PEM_VERSION_TO_REPLACE = "__PEM_VERSION_TO_REPLACE__";
        public final static String BASE_LOGIC_TABLE_NAME = "device_warehouse___";
        public final static String ORIGIN_DEVICE_WAREHOUSE_TABLE_NAME_SUFFIX = "_device_warehouse";

        public final static String LOGIC_TABLE_NAME = "__LOGIC_TABLE_NAME__";
        public final static String STATUS_TO_REPLACE = "__STATUS_TO_REPLACE__";
        public final static String SHARDING_KEY_TO_REPLACE = "__SHARDING_KEY_TO_REPLACE__";
        public final static String BATCH_CODE_TO_REPLACE = "__BATCH_CODE_TO_REPLACE__";
        public final static String SUB_DOMAIN_TO_REPLACE = "__SUB_DOMAIN_TO_REPLACE__";
        public final static String LIMIT_TO_REPLACE = "__LIMIT_TO_REPLACE__";
        public final static String OFFSET_TO_REPLACE = "__OFFSET_TO_REPLACE__";

        public final static String SELECT_BY_BATCH_CODE = "select count(*) from __LOGIC_TABLE_NAME__ where batch_code = '__BATCH_CODE_TO_REPLACE__'";
        public final static String SELECT_BY_SUB_DOMAIN_PREFIX = "select * from __LOGIC_TABLE_NAME__ where device_id IS NOT NULL ";
        public final static String SELECT_COUNT_BY_SUB_DOMAIN_PREFIX = "select count(*) from __LOGIC_TABLE_NAME__ where device_id IS NOT NULL ";
        public final static String SELECT_COUNT_BY_SUB_DOMAIN_SUFFIX = " and sub_domain = '__SUB_DOMAIN_TO_REPLACE__'";
        public final static String SELECT_BY_SUB_DOMAIN_SUFFIX = " and sub_domain = '__SUB_DOMAIN_TO_REPLACE__' limit __LIMIT_TO_REPLACE__ offset __OFFSET_TO_REPLACE__";
        public final static String SELECT_ALL_OFFSET = "select code, device_id, sub_domain, public_key, status, create_time, modify_time, batch_code, pem_version from __LOGIC_TABLE_NAME__ where device_id IS NOT NULL and CHAR_LENGTH(device_id) = 36 and device_id like '86%' order by `device_id` ASC limit __LIMIT_TO_REPLACE__ offset __OFFSET_TO_REPLACE__ ";

        public final static String SELECT_ALL_COUNT = "select count(*) from __LOGIC_TABLE_NAME__ where device_id IS NOT NULL and CHAR_LENGTH(device_id) = 36 and device_id like '86%'";
        public final static String SELECT_BY_WIFI_ID = "select * from __LOGIC_TABLE_NAME__ where device_id = '__WIFI_ID_TO_REPLACE__' and sharding_key = __SHARDING_KEY_TO_REPLACE__";
        public final static String UPDATE_STATUS = "update __LOGIC_TABLE_NAME__ set status = __STATUS_TO_REPLACE__, update_time=UTC_TIMESTAMP() where device_id = '__WIFI_ID_TO_REPLACE__' and sharding_key = __SHARDING_KEY_TO_REPLACE__ ";
        public final static String UPDATE_PEM_VERSION = "update __LOGIC_TABLE_NAME__ set pem_version = __PEM_VERSION_TO_REPLACE__, update_time=UTC_TIMESTAMP() where device_id = '__WIFI_ID_TO_REPLACE__' and sharding_key = __SHARDING_KEY_TO_REPLACE__ ";

        public final static String INSERT_PREFIX = "INSERT INTO __LOGIC_TABLE_NAME__ (id, domain, sub_domain, device_id, public_key, status, batch_code, sharding_key, create_time, update_time) VALUES ";
        public final static String INSERT_SUFFIX = " ON DUPLICATE KEY UPDATE domain=values(domain), sub_domain=values(sub_domain), public_key=values(public_key), update_time=UTC_TIMESTAMP(), create_time=UTC_TIMESTAMP(), status=values(status), batch_code=values(batch_code), sharding_key=values(sharding_key)";

        public final static String CREATE_JULINK_WAREHOUSE_DB = "create database if not exists julink_warehouse default character set utf8 collate utf8_unicode_ci;";
        public final static String CREATE_DEVICE_TEMPLATE_TABLE = """
                CREATE TABLE IF NOT EXISTS __DOMAIN___julink_warehouse___SERIAL_ID__
                  (
                      `id`           varchar(64) PRIMARY KEY NOT NULL COMMENT 'snowflake id',
                      `domain`       varchar(64)                  DEFAULT NULL,
                      `sub_domain`   varchar(64)                  DEFAULT NULL,
                      `device_id`    varchar(200) UNIQUE          DEFAULT NULL,
                      `public_key`   varchar(255)                 DEFAULT NULL,
                      `status`       int(4)                       DEFAULT 0,
                      `batch_code`   varchar(64)                  DEFAULT NULL,
                      `sharding_key` bigint                 DEFAULT 0,
                      `create_time`  timestamp               NULL DEFAULT CURRENT_TIMESTAMP,
                      `update_time`  timestamp               NULL DEFAULT CURRENT_TIMESTAMP,
                      `del_flag`     int(10)                      DEFAULT 0
                  ) ENGINE = InnoDB
                    CHARACTER SET = utf8mb4
                    COLLATE = utf8mb4_general_ci;
                """;
        public final static String DOMAIN_ID_TO_REPLACE = "__DOMAIN__";
        public final static String SERIAL_ID_TO_REPLACE = "__SERIAL_ID__";

        public final static String CREATE_DEVICE_LICENSES_TABLE = """
                    CREATE TABLE IF NOT EXISTS `__DOMAIN___device_licenses` (
                              `license` varchar(128) COLLATE utf8mb4_general_ci NOT NULL,
                              `sub_domain` varchar(32) COLLATE utf8mb4_general_ci NOT NULL,
                              `req_id` bigint NOT NULL,
                              `create_time` datetime NOT NULL,
                              PRIMARY KEY (`license`),
                              KEY `req_id` (`req_id`)
                            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
                """;

        public final static String CREATE_DEVICE_PROPERTY_TABLE = """
                    CREATE TABLE IF NOT EXISTS `__DOMAIN___device_property` (
                              `device_id` varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
                              `sub_domain` varchar(32) COLLATE utf8mb4_general_ci NOT NULL,
                              `channel` varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
                              `batch` varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
                              `create_time` datetime DEFAULT NULL,
                              `modify_time` datetime DEFAULT NULL,
                              PRIMARY KEY (`device_id`)
                            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
                """;

        public final static String CREATE_FAILED_DEVICE_LICENSES_TABLE = """
                CREATE TABLE IF NOT EXISTS `__DOMAIN___failed_device_licenses` (
                  `license` varchar(128) COLLATE utf8mb4_general_ci NOT NULL,
                  `sub_domain` varchar(32) COLLATE utf8mb4_general_ci NOT NULL,
                  `status` int NOT NULL,
                  `used_time` bigint NOT NULL,
                  `create_time` datetime NOT NULL,
                  PRIMARY KEY (`license`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
                        """;

        public final static String CREATE_DEVICE_ATOM_TABLE = """
                CREATE TABLE IF NOT EXISTS `__DOMAIN___device_atom` (
                  `logical_id` bigint NOT NULL AUTO_INCREMENT,
                  `sub_domain` varchar(32) COLLATE utf8mb4_general_ci NOT NULL,
                  `physical_id` varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
                  `create_time` datetime DEFAULT NULL,
                  `modify_time` datetime DEFAULT NULL,
                  PRIMARY KEY (`logical_id`),
                  UNIQUE KEY `sub_domain` (`sub_domain`,`physical_id`)
                ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
                                """;
    }

    public static class Product {
        public final static String CANNOT_BE_EMPTY = " ";
    }

    public static class Platform {
        public final static Long ID_NOT_FOUND = -1L;
        public final static int STATUS_ENABLE = 0;
        public final static int STATUS_DISABLE = 1;
    }

    public static class DS {
        public final static String SHARDING_JDBC = "sharding";
        public final static String PRODUCT = "product";
        public final static String PLATFORM = "platform";
        public final static String JULINK_WAREHOUSE = "julink_warehouse";

    }

    public static class AMQConfig {
        public final static String MSG_TYPE_BLACK_LIST = "_BLACK_LIST_";
        public final static String MSG_TYPE_CLEAN_CACHE = "_CLEAN_CACHE_";
    }
}
